package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.ToEasyService;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealPageVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface SetmealMapper {

    @ToEasyService
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into setmeal(category_id, name, price, status, description, image, create_time, update_time, create_user, update_user) " +
            "values (#{categoryId},#{name},#{price},#{status},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void insertSetmeal(Setmeal setmeal);


    void insertSetmealDishes(List<SetmealDish> setmealDishes);


    Page<SetmealPageVO> page(SetmealPageQueryDTO setmealPageQueryDTO);


    void update(SetmealDTO setmealDTO);


    void delete(Integer[] ints);


    void deleteDish(Integer deleteMealDish);

    //没有查到dish
    SetmealVO getById(@Param("id") int id);


    List<SetmealDish> getDishById(@Param("id") int id);

    @Update("update setmeal set status=#{status} where id=#{id}")
    void updateStatus(String status, int id);

    @Select("select count(status) from setmeal where status=#{enable}")
    int selectStatusCount(@Param("enable") Integer enable);

    @Select("select * from setmeal s where s.category_id = #{categoryId}")
    List<Setmeal> getSetmealByCategoryId(String categoryId);


    @Select("select dish_id id,copies from setmeal_dish  where setmeal_id = #{id}")
    List<DishVO> getDishesForUserBySetmealId(Integer id);
}
